package com.ding.controller.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.ding.pojo.User;
import com.ding.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	UserService service;
	
	@GetMapping("/login")
	public String login(@RequestParam(value = "error", required = false) String error,Model model) {
		if (error!=null) {
			model.addAttribute("error","用户名或密码错误!!!");
		}
		return "user/login";
	}
	@RequestMapping(value="/regist",method=RequestMethod.GET)
	public String registGET(Model model) {
		model.addAttribute(new User());
		return "user/regist";
	}
	
	@RequestMapping(value="regist",method=RequestMethod.POST)
	public String registPOST(User user) {
		service.save(user);
		return "redirect:/user/login";
	}
	
}
